package com.itheima.controller;

import com.itheima.pojo.*;
import com.itheima.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
@RequiredArgsConstructor
public class UserController {
    //加final
    private final UserService userService;

    /**
     * 分页查询
     */
    @GetMapping
    public Result page( PageQuery pageQuery){
        PageResult pageResult = userService.page(pageQuery.getPage(),pageQuery.getPageSize(),pageQuery.getName(),pageQuery.getGender());
        return Result.success(pageResult);
    }

    /**
     * 登录
     */
    @PostMapping("/login")
    public Result login(@RequestBody User user){
        LoginInfo loginInfo =  userService.login(user);
        if (loginInfo!=null){
            return Result.success(loginInfo);
        }
        return Result.error("登录失败");
    }
}
